package com.leyou.item.comtroller;

import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.entity.SpecGroup;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author LT
 * @version 1.0.0
 * @ClassName SpecController.java
 * @Description TODO 规格控制器
 * @createTime 2020年05月06日 17:20:00
 */
@RestController
public class SpecController {

    @Autowired
    private SpecService specService;

    @GetMapping("/spec/groups/of/category")
    public ResponseEntity<List<SpecGroup>> findSpecGroupsByCid(@RequestParam("id") Long id) {
        List<SpecGroup> groups = specService.findSpecGroupsByCid(id);
        return ResponseEntity.ok(groups);

    }

    /**
     * 查询规格参数列表
     *
     * @param gid
     * @param cid
     * @param searching
     * @return
     */
    @GetMapping("/spec/params")
    public ResponseEntity<List<SpecParam>> findSpecParams(
            @RequestParam(value = "gid", required = false) Long gid,
            @RequestParam(value = "cid", required = false) Long cid,
            @RequestParam(value = "searching", required = false) Boolean searching
    ) {
        List<SpecParam> specParams = specService.findSpecParams(gid, cid, searching);
        return ResponseEntity.ok(specParams);
    }

    /**
     *  根据categoryId查询规格参数组和组内参数(根据第三级分类id查询规格组和组内参数)
     * @param cid
     * @return
     */
    @GetMapping("/spec/of/category")
    public ResponseEntity<List<SpecGroupDTO>> findSpecGroupByCid(@RequestParam("id") Long cid) {
        List<SpecGroupDTO> specGroupDTOS = specService.findSpecGroupByCid(cid);
        return ResponseEntity.ok(specGroupDTOS);
    }

}
